package com.shrcl.engineerprocess.domain.impl;

import com.shrcl.engineerprocess.domain.CertificationNotification;
import com.shrcl.engineerprocess.domain.Engineer;
import com.shrcl.engineerprocess.domain.EngineerCertification;
import com.shrcl.engineerprocess.domain.EngineerNotifyReceiver;
import com.shrcl.engineerprocess.domain.NotificationSender;
import com.shrcl.engineerprocess.domain.impl.EngineerCertificationImpl;
import com.shrcl.engineerprocess.domain.impl.NotificationImpl;
import com.shrcl.engineerprocess.domain.proxy.CertificationNotificationProxy;
import edu.fudan.mylang.pf.IObjectFactory;
import javax.persistence.CascadeType;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import org.eclipse.xtext.xbase.lib.InputOutput;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.springframework.beans.factory.BeanFactory;

@Entity
@DiscriminatorValue("CERTIFICATIONNOTIFICATION_TYPE")
public class CertificationNotificationImpl extends NotificationImpl implements CertificationNotification {
  public CertificationNotificationImpl() {
    super();
  }
  
  @JoinColumn(name = "engineerCertification_id")
  @ManyToOne(targetEntity = EngineerCertificationImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST })
  private EngineerCertification engineerCertification;
  
  public EngineerCertification getEngineerCertification() {
    return this.engineerCertification;
  }
  
  public CertificationNotification setEngineerCertification(final EngineerCertification engineerCertification) {
    this.engineerCertification = engineerCertification;
    return this;			
    
  }
  
  public void doNotify() {
    InputOutput.<String>println("============>send CertificationNotification invoke");
    Engineer _engineer = this.engineerCertification.getEngineer();
    EngineerNotifyReceiver _asNotifyReceiver = _engineer.asNotifyReceiver();
    this.setReceiver(_asNotifyReceiver);
    BeanFactory _beanFactory = this.getBeanFactory();
    final NotificationSender notificationSender = _beanFactory.<NotificationSender>getBean(NotificationSender.class);
    notificationSender.sendNotification(this);
  }
  
  public void init() {
    this.setNotificationType("CertificationNotification");
  }
  
  public static CertificationNotification create(final IObjectFactory objectFactory) {
    com.shrcl.engineerprocess.domain.CertificationNotification certificationNotification = new com.shrcl.engineerprocess.domain.impl.CertificationNotificationImpl(
    );
    objectFactory.create(certificationNotification);
    return certificationNotification;			
    
  }
  
  public static CertificationNotification createCertificationNotificationImpl(final IObjectFactory objectFactory, final Procedure1<CertificationNotification> init) {
    com.shrcl.engineerprocess.domain.CertificationNotification certificationNotification = new com.shrcl.engineerprocess.domain.impl.CertificationNotificationImpl(
    );
    objectFactory.create(certificationNotification);
    init.apply(certificationNotification);
    
    return certificationNotification;			
    
  }
  
  public CertificationNotificationProxy toProxy() {
    com.shrcl.engineerprocess.domain.proxy.CertificationNotificationProxy proxy = new com.shrcl.engineerprocess.domain.proxy.CertificationNotificationProxy();
    proxy.setId(this.getId());
    if(this instanceof edu.fudan.mylang.pf.INamedModelObject){
    	proxy.setName(((edu.fudan.mylang.pf.INamedModelObject)this).getEntityName());
    }
    return proxy;
    
  }
}
